package com.gimi.cloud.bbp.client.controller.moreInfo;

import com.gimi.cloud.bbp.client.service.moreInfo.SocialSecurityService;
import com.gimi.cloud.bbp.common.constant.RedisKeyConstant;
import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.utils.JsonUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.common.utils.reqhead.Util;
import com.gimi.cloud.bbp.commonService.InterfacePlatform.impl.InterfaceUtil;
import com.gimi.cloud.bbp.commonService.redis.RedisService;
import com.gimi.cloud.bbp.dto.params.SocialSecurityParam;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 蜂巢社保
 *
 * @author zhoufuhang
 * @time 2018年1月9日
 */
@RestController
@RequestMapping("/moreInfo")
public class SocialSecurityController {
    private InterfaceUtil interfaceUtil;
    private RedisService redisService;
    private SocialSecurityService socialSecurityService;

    @Autowired
    public SocialSecurityController(InterfaceUtil interfaceUtil, RedisService redisService
            ,SocialSecurityService socialSecurityService) {
        this.interfaceUtil = interfaceUtil;
        this.redisService = redisService;
        this.socialSecurityService=socialSecurityService;
    }

    /**
     * 获取城市列表
     */
    @RequestMapping("/getSheBaoCityList")
    public void getSheBaoCityList(@RequestBody SocialSecurityParam socialSecurityParam, HttpServletResponse response) {
        String result = redisService.get(RedisKeyConstant.INTERFACE_PLATFORM_FENGCHAO_SHEBAO_CITY);
        Util.sendResponseFastJson(JSONArray.fromObject(result), ResponseCodeEnum.SUCCESSED, response);
    }

    /**
     * 获取登录参数
     */
    @RequestMapping("/getSheBaoCityLoginParamer")
    public void getSheBaoCityLoginParamer(@RequestBody SocialSecurityParam socialSecurityParam, HttpServletResponse response) {
        socialSecurityParam.setRedisKey(RedisKeyConstant.INTERFACE_PLATFORM_UNIVERSAL_SOCIALSECURITY);
        socialSecurityParam.setInterfcaeParamKey("getcitylogin");
        socialSecurityParam.setInterfcaeResultKey("check");
        Util.sendResponseFastJson(interfaceUtil.call(socialSecurityParam), ResponseCodeEnum.SUCCESSED, response);
    }

    /**
     * 获取验证码图片
     */
    @RequestMapping("/getSheBaoCodeImage")
    public void getSheBaoCodeImage(@RequestBody SocialSecurityParam socialSecurityParam, HttpServletResponse response) {
        socialSecurityParam.setRedisKey(RedisKeyConstant.INTERFACE_PLATFORM_UNIVERSAL_SOCIALSECURITY);
        socialSecurityParam.setInterfcaeParamKey("getcodeimage");
        socialSecurityParam.setInterfcaeResultKey("check");
        Util.sendResponseFastJson(interfaceUtil.call(socialSecurityParam), ResponseCodeEnum.SUCCESSED, response);
    }

    /**
     * 登录并抓取社保账号
     * @throws Exception
     */
	@RequestMapping("/getSheBaoLoginAndGrab")
	public void getSheBaoLoginAndGrab(@RequestBody SocialSecurityParam socialSecurityParam, HttpServletResponse response) throws Exception {
        Response resp= socialSecurityService.getSheBaoLoginAndGrab(socialSecurityParam);
        Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp), response);
	}

}
